package Form;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import Control.Shop_Product_Controller;

@SuppressWarnings("serial")
public class Shop_Product_Search_Form extends JPanel {
	private JLabel lblHeader;
	private JScrollPane scrollPane;
	
	private Main parser;
	private Shop_Product_Controller control;
	private JPanel products;
	private JPanel panel;
	private JLabel backgroundImage;
	
	public Main getParser() {
		return parser;
	}

	public void setParser(Main parser) {
		this.parser = parser;
	}

	public Shop_Product_Controller getControl() {
		return control;
	}

	public void setControl(Shop_Product_Controller control) {
		this.control = control;
	}
	
	public void search(){
		getControl().search();
	}

	public Shop_Product_Search_Form(Main parser) {
		setParser(parser);
		setControl(new Shop_Product_Controller(this));
		
		this.setOpaque(false);
		
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		GridBagConstraints gbc_lblHeader = new GridBagConstraints();
		gbc_lblHeader.fill = GridBagConstraints.HORIZONTAL;
		gbc_lblHeader.gridx = 0;
		gbc_lblHeader.gridy = 0;
		add(getLblHeader(), gbc_lblHeader);
		getPanel().setLayout(null);
		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.fill = GridBagConstraints.BOTH;
		gbc_panel.gridx = 0;
		gbc_panel.gridy = 1;
		add(getPanel(), gbc_panel);
	}

	public JLabel getLblHeader() {
		if (lblHeader == null) {
			lblHeader = new JLabel("Search Result");
			lblHeader.setFont(new Font("Tahoma", Font.PLAIN, 23));
			lblHeader.setOpaque(true);
			lblHeader.setBackground(Color.decode("#002640"));
			lblHeader.setForeground(Color.WHITE);
			lblHeader.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.decode("#002640")));
		}
		return lblHeader;
	}
	public JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(0, 0, 595, 533);
			scrollPane.setOpaque(false);
			scrollPane.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.decode("#002640")));
			scrollPane.setViewportView(getProducts());
			scrollPane.getViewport().setOpaque(false);
		}
		return scrollPane;
	}
	public JPanel getProducts() {
		if (products == null) {
			products = new JPanel();
			products.setOpaque(false);
			FlowLayout flowLayout = (FlowLayout) products.getLayout();
			flowLayout.setAlignment(FlowLayout.LEFT);
		}
		return products;
	}
	public JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.add(getScrollPane());
			panel.add(getBackgroundImage());
		}
		return panel;
	}
	public JLabel getBackgroundImage() {
		if (backgroundImage == null) {
			backgroundImage = new JLabel();
			backgroundImage.setOpaque(true);
			backgroundImage.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage("Resources/Images/Backgrounds/orange_checkered.png").getScaledInstance(595, 533, Image.SCALE_DEFAULT)));
			backgroundImage.setBounds(0, 0, 595, 533);
		}
		return backgroundImage;
	}
}
